//
//  ViewController.swift
//  剂查查
//
//  Created by shoubin tao on 2024/11/30.
//  Copyright © 2024 shipin. All rights reserved.
//  首页!!!!!!!!!

import CommonTools
import TYAlertView
import AppTrackingTransparency
import CJMobileAd

class JCCScanTipViewController: UIViewController,CJSplashAdDelegate {
    
    var splashAd : CJSplashAd?
    
    override func viewWillAppear(_ animated: Bool) {
        
        self.navigationController?.navigationBar.isHidden = true
        self.navigationController?.interactivePopGestureRecognizer?.delegate = nil
    }

    override func viewWillDisappear(_ animated: Bool) {
        self.navigationController?.navigationBar.isHidden = false
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // 申请IDFA授权
        if #available(iOS 14, *) {
            ATTrackingManager.requestTrackingAuthorization { status in
                print("申请授权结果\(status)")
            }
        }
        
        splashAd = CJSplashAd(resourceId: "8a4965ae2b5f4ce6", window: UIApplication.shared.keyWindow!, rootViewController: self, customLogoView: UIView())
        splashAd!.delegate = self
        splashAd!.loadData()
    }
    
//    func splashAd(onShow splashAd: CJSplashAd) {
//        print("展示成功")
//    }
//    
//    func splashAdLoadFailed(_ splashAd: CJSplashAd, error: any Error) {
//        print("展示失败\(error)")
//    }
        
    @IBAction func toScan(_ sender: UIButton) {
        let  authorizationStatus = AVCaptureDevice.authorizationStatus(for: .video)
        if (authorizationStatus == .restricted || authorizationStatus == .denied) {
            TYAlertView.showCommonAlert(message: "APP需要获取您的相机权限，用于扫描二维码链接设备", buttonTitles: ["去设置"], cancelButtonTitle: "取消") { alert, index in
                if index == 1 {
                    UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!, completionHandler: nil)
                }
            }
            return
        }
        pushToSBVC(name: "JCCScanViewController")
    }
    
}

